﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace _07_控件
{
    /// <summary>
    /// _03_CheckBox.xaml 的交互逻辑
    /// </summary>
    public partial class _03_CheckBox : Window
    {
        public _03_CheckBox()
        {
            InitializeComponent();
        }

        private void ListBox_Click(object sender, RoutedEventArgs e)
        {
            if(e.OriginalSource is CheckBox  cb)
            {
                this.listBox.SelectedItem = cb;

            }
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string result = "";
            foreach (var item in listBox.Items)
            {
                if (item is CheckBox cb)
                {
                    if (cb.IsChecked == true) {
                        result += cb.Content;
                    }
                   
                }
            }
            MessageBox.Show(result);
        }
    }
}
